package com.ybkj.o2o.sales.controller.res;

import com.google.common.base.Preconditions;

import com.ybkj.o2o.sales.common.ActivityVo;
import com.ybkj.o2o.sales.common.DataGrid;
import com.ybkj.o2o.sales.common.transport.Error;
import com.ybkj.o2o.sales.common.transport.Result;
import com.ybkj.o2o.sales.entity.Activity;
import com.ybkj.o2o.sales.entity.Activity.ActivityEvent;
import com.ybkj.o2o.sales.entity.Activity.ActivityTarget;
import com.ybkj.o2o.sales.entity.Activity.ActivityType;
import com.ybkj.o2o.sales.entity.Activity.OrderType;
import com.ybkj.o2o.sales.entity.ActivityRecord;
import com.ybkj.o2o.sales.manager.ActivityManager;
import com.ybkj.o2o.sales.manager.CouponRuleManager;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping(value = "api/activity")
public class ActivityRes {
  @Autowired
  private CouponRuleManager couponRuleManager;
  @Autowired
  private ActivityManager activityManager;

  /**
   * 根据条件分页查询活动.
   * 
   * @param companyId 公司id
   * @param activityEvent 活动事件
   * @param activityType 活动类型
   * @param page 页数
   * @param rows 每页数量
   * @param appKey 系统可以
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "queryActivities", method = RequestMethod.GET)
  public ResponseEntity<Object> queryActivities(
      @RequestParam(required = false, value = "companyId") Long companyId, @RequestParam(
          required = true, value = "activityEvent") String activityEvent, @RequestParam(
          required = false, value = "activityType") String activityType, @RequestParam(
          required = false, value = "page") Integer page, @RequestParam(required = false,
          value = "rows") Integer rows,
      @RequestParam(required = true, value = "appKey") String appKey) {

    ResponseEntity<Object> responseEntity = null;

    try {
      DataGrid<Activity> activity =
          activityManager.queryActivities(companyId, activityEvent, activityType, page, rows,
              appKey);
      System.out.println("ActivityRes.queryActivities()" + companyId);
      Result<DataGrid<Activity>> result = new Result<DataGrid<Activity>>(0, "成功", activity);
      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {
      ex.printStackTrace();
      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());

      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

      return responseEntity;
    }

  }

  /**
   * 分页查询所有活动信息.
   *
   * @param companyId 公司id
   * @param page 页数
   * @param rows 每页数量
   * @param appKey 系统key
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "activityAll", method = RequestMethod.GET)
  public ResponseEntity<Object> activityAll(
      @RequestParam(required = false, value = "companyId") Long companyId, @RequestParam(
          required = false, value = "page") Integer page, @RequestParam(required = false,
          value = "rows") Integer rows,
      @RequestParam(required = true, value = "appKey") String appKey) {

    ResponseEntity<Object> responseEntity = null;

    try {
      DataGrid<Activity> activity = activityManager.activityAll(companyId, page, rows, appKey);

      Result<DataGrid<Activity>> result = new Result<DataGrid<Activity>>(0, "成功", activity);
      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {
      ex.printStackTrace();
      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());

      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

      return responseEntity;
    }

  }


  /**
   * 新增活动.
   *
   * @param activityEvent 活动事件
   * @param activityTarget 活动对象
   * @param activityType 活动类型
   * @param gradeIds 客户等级id
   * @param gradeNames 客户等级名称
   * @param passengerFromSource 客户来源
   * @param sharePlatforms 分享渠道
   * @param sharePlatformNames 分享渠道名称
   * @param shareTimes 满足的分享次数
   * @param restriction 限制领取次数
   * @param orderFromSource 订单来源
   * @param completeTimes 每完成completeTimes次活动 奖励
   * @param orderType 订单类型
   * @param companyIds 公司id
   * @param companyNames 公司名称
   * @param start 开始时间
   * @param end 结束时间
   * @param money 返现金额
   * @param couponIds 优惠券id
   * @param couponAmounts 优惠券数量
   * @param messageType 通知方式
   * @param companyId 创建人公司id
   * @param backgroudColor 背景颜色
   * @param activityContent 活动规则
   * @param activityImage 活动图片
   * @param freeType 首单免费类型 0全部免费 1按照百分比免除金额 2自定义
   * @param otherMoney 自定义价格
   * @param appKey 系统key
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "create", method = RequestMethod.POST)
  public ResponseEntity<Object> create(
      @RequestParam(required = true, value = "activityEvent") String activityEvent,
      @RequestParam(required = false, value = "activityTarget") String activityTarget,
      @RequestParam(required = false, value = "activityType") String activityType,
      @RequestParam(required = false, value = "gradeIds") String gradeIds,
      @RequestParam(required = false, value = "gradeNames") String gradeNames,
      @RequestParam(required = false, value = "passengerFromSource") String passengerFromSource,
      @RequestParam(required = false, value = "sharePlatforms") String sharePlatforms,
      @RequestParam(required = false, value = "sharePlatformNames") String sharePlatformNames,
      @RequestParam(required = false, value = "shareTimes") Integer shareTimes,
      @RequestParam(required = false, value = "restriction") Integer restriction,
      @RequestParam(required = false, value = "orderFromSource") String orderFromSource,
      @RequestParam(required = false, value = "completeTimes") Integer completeTimes,
      @RequestParam(required = false, value = "orderType") String orderType,
      @RequestParam(required = true, value = "companyIds") String companyIds,
      @RequestParam(required = true, value = "companyNames") String companyNames,
      @RequestParam(required = true, value = "start") Long start,
      @RequestParam(required = false, value = "end") Long end,
      @RequestParam(required = false, value = "money") BigDecimal money,
      @RequestParam(required = false, value = "couponIds") String couponIds,
      @RequestParam(required = false, value = "couponAmounts") String couponAmounts,
      @RequestParam(required = false, value = "messageType") String messageType,
      @RequestParam(required = true, value = "companyId") Long companyId,
      @RequestParam(required = false, value = "backgroudColor") String backgroudColor,
      @RequestParam(required = false, value = "activityContent") String activityContent,
      @RequestParam(required = false, value = "activityImage") String activityImage,
      @RequestParam(required = false, value = "freeType") Integer freeType,
      @RequestParam(required = false, value = "otherMoney") BigDecimal otherMoney,
      @RequestParam(required = false, value = "rechargingMoney") BigDecimal rechargingMoney,
      @RequestParam(required = true, value = "appKey") String appKey,
      @RequestParam(required = false, value = "lineId") Long lineId,
      @RequestParam(required = false, value = "lineName") String lineName) {

    ResponseEntity<Object> responseEntity = null;

    try {

      Activity activity = new Activity();
      //设置线路相关
      if(null != lineId) activity.setLineId(lineId);
      if(null != lineName) activity.setLineName(lineName);

      activity.setActivityEvent(ActivityEvent.valueOf(activityEvent));
      if (null != activityTarget) {
        activity.setActivityTarget(ActivityTarget.valueOf(activityTarget));
      }
      if (null != activityType) {
        activity.setActivityType(ActivityType.valueOf(activityType));
      }
      activity.setGradeIds(gradeIds);
      activity.setGradeNames(gradeNames);
      activity.setPassengerFromSource(passengerFromSource);
      activity.setMoney(money);
      activity.setCouponIds(couponIds);
      activity.setCouponAmounts(couponAmounts);

      activity.setCompanyIds(companyIds);
      activity.setCompanyNames(companyNames);

      activity.setStart(new Date(start));
      if (null != end) {
        activity.setEnd(new Date(end));
      }

      // 分享成功相关
      activity.setSharePlatforms(sharePlatforms);
      activity.setSharePlatformNames(sharePlatformNames);
      activity.setShareTimes(shareTimes);
      activity.setRestriction(restriction);

      // 完成订单相关
      activity.setOrderFromSource(orderFromSource);
      if (null != completeTimes) {
        activity.setCompleteTimes(completeTimes);
      }
      if (null != orderType) {
        activity.setOrderType(OrderType.valueOf(orderType));
      }

      activity.setMessageType(messageType);

      activity.setCompanyId(companyId);

      // 根据手机号赠送优惠券相关
      activity.setBackgroudColor(backgroudColor);
      activity.setActivityImage(activityImage);
      activity.setActivityContent(activityContent);

      // 首单免费相关
      activity.setFreeType(freeType);
      activity.setOtherMoney(otherMoney);

      // 充值满相关
      activity.setRechargingMoney(rechargingMoney);

      activity.setAppKey(appKey);


      activity = activityManager.insert(activity);

      Result<Activity> result = new Result<Activity>(0, "成功", activity);
      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {
      ex.printStackTrace();
      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());

      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

      return responseEntity;
    }

  }

  /**
   * 修改活动.
   * 
   * @param id 活动id
   * @param activityTarget 活动对象
   * @param gradeIds 客户等级id
   * @param gradeNames 客户等级名称
   * @param passengerFromSource 客户来源
   * @param sharePlatforms 分享渠道
   * @param sharePlatformNames 分享渠道名称
   * @param orderFromSource 订单来与
   * @param companyIds 参与活动公司id
   * @param companyNames 参与活动公司名称
   * @param end 结束时间
   * @param messageType 通知方式
   * @param backgroudColor 背景颜色
   * @param activityContent 活动规则
   * @param activityImage 活动背景图片
   * @param appKey 系统key
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "update", method = RequestMethod.POST)
  public ResponseEntity<Object> update(@RequestParam(required = true, value = "id") Long id,
      @RequestParam(required = false, value = "activityTarget") String activityTarget,
      @RequestParam(required = false, value = "gradeIds") String gradeIds, @RequestParam(
          required = false, value = "gradeNames") String gradeNames, @RequestParam(
          required = false, value = "passengerFromSource") String passengerFromSource,
      @RequestParam(required = false, value = "sharePlatforms") String sharePlatforms,
      @RequestParam(required = false, value = "sharePlatformNames") String sharePlatformNames,
      @RequestParam(required = false, value = "orderFromSource") String orderFromSource,
      @RequestParam(required = true, value = "companyIds") String companyIds, @RequestParam(
          required = true, value = "companyNames") String companyNames, @RequestParam(
          required = false, value = "end") Long end, @RequestParam(required = false,
          value = "messageType") String messageType, @RequestParam(required = false,
          value = "backgroudColor") String backgroudColor, @RequestParam(required = false,
          value = "activityContent") String activityContent, @RequestParam(required = false,
          value = "activityImage") String activityImage, @RequestParam(required = true,
          value = "appKey") String appKey) {

    ResponseEntity<Object> responseEntity = null;
    try {

      Activity activity = activityManager.findOne(id, appKey);
      if (activity == null) {
        Error error = new Error(500, "查询不到活动！");

        responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

        return responseEntity;
      }

      if (null != activityTarget) {
        activity.setActivityTarget(ActivityTarget.valueOf(activityTarget));
      }
      activity.setGradeIds(gradeIds);
      activity.setGradeNames(gradeNames);
      activity.setPassengerFromSource(passengerFromSource);

      activity.setCompanyIds(companyIds);
      activity.setCompanyNames(companyNames);

      if (null != end) {
        activity.setEnd(new Date(end));
      } else {
        activity.setEnd(null);
      }

      // 分享成功相关
      activity.setSharePlatforms(sharePlatforms);
      activity.setSharePlatformNames(sharePlatformNames);

      // 完成订单相关
      activity.setOrderFromSource(orderFromSource);

      activity.setMessageType(messageType);

      // 根据手机号赠送优惠券相关
      activity.setBackgroudColor(backgroudColor);
      activity.setActivityImage(activityImage);
      activity.setActivityContent(activityContent);

      activityManager.update(activity);

      Result<Activity> result = new Result<Activity>(0, "成功", activity);
      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {
      ex.printStackTrace();

      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());

      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

      return responseEntity;
    }

  }

  /**
   * 根据手机号赠送优惠券.
   * 
   * @param backgroudColor 背景颜色
   * @param activityType 活动类型
   * @param companyIds 公司id
   * @param companyNames 公司名称
   * @param gradeIds 客户等级id
   * @param gradeNames 客户等级名称
   * @param activityImage 背景图片
   * @param activityTarget 活动对象
   * @param activityEvent 活动事件
   * @param start 开始时间
   * @param end 结束时间
   * @param completeTimes 每完成completeTimes次订单业务 奖励
   * @param restriction 每人限制领取次数
   * @param orderType 订单类型
   * @param money 返现金额
   * @param couponRuleId 优惠券规则id
   * @param amount 优惠券数量
   * @param activityContent活动规则
   * @param appKey 系统key
   * @return ResultTransport{code,message,data}
   */

  @RequestMapping(value = "phonecoupon", method = RequestMethod.GET)
  public ResponseEntity<Object> phoneCoupon(@RequestParam(required = false,
      value = "backgroudColor") String backgroudColor, @RequestParam(required = false,
      value = "activityType") String activityType, @RequestParam(required = false,
      value = "companyIds") String companyIds, @RequestParam(required = false,
      value = "companyNames") String companyNames, @RequestParam(required = false,
      value = "gradeIds") String gradeIds,
      @RequestParam(required = false, value = "gradeNames") String gradeNames, @RequestParam(
          required = false, value = "activityImage") String activityImage, @RequestParam(
          required = false, value = "activityTarget") String activityTarget, @RequestParam(
          required = false, value = "activityEvent") String activityEvent, @RequestParam(
          required = false, value = "start") String start, @RequestParam(required = false,
          value = "end") String end,
      @RequestParam(required = false, value = "completeTimes") Integer completeTimes,
      @RequestParam(required = false, value = "restriction") Integer restriction, @RequestParam(
          required = false, value = "orderType") String orderType, @RequestParam(required = false,
          value = "money") BigDecimal money,
      @RequestParam(required = false, value = "couponRuleId") String couponRuleId, @RequestParam(
          required = false, value = "amount") String amount, @RequestParam(required = false,
          value = "activityContent") String activityContent, @RequestParam("appKey") String appKey) {

    ResponseEntity<Object> responseEntity = null;
    appKey = StringUtils.trimToEmpty(appKey);
    Preconditions.checkArgument(StringUtils.isNotBlank(appKey), "AppKey不能为空");
    try {
      Activity activity = new Activity();
      SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
      Date endTime = null;
      Date startTime = sf.parse(start);
      if (StringUtils.isNotBlank(end)) {
        endTime = sf.parse(end);
      }
      activity.setBackgroudColor(backgroudColor);
      activity.setActivityType(ActivityType.valueOf(activityType));
      activity.setActivityTarget(ActivityTarget.valueOf(activityTarget));
      activity.setActivityEvent(ActivityEvent.valueOf(activityEvent));
      activity.setStart(startTime);
      if (endTime != null) {
        activity.setEnd(endTime);
      }
      activity.setCompanyIds(companyIds);
      activity.setCompanyNames(companyNames);
      activity.setGradeIds(gradeIds);
      activity.setGradeNames(gradeNames);
      activity.setCouponIds(couponRuleId);
      activity.setCouponAmounts(amount);
      activity.setActivityContent(activityContent);
      activity.setActivityImage(activityImage);
      activity.setCompleteTimes(completeTimes);
      activity.setOrderType(OrderType.valueOf(orderType));
      activity.setRestriction(restriction);
      activity.setMoney(money);
      activity.setAppKey(appKey);
      activity = activityManager.insert(activity);

      Result<Activity> result = new Result<Activity>(0, "成功", activity);

      responseEntity = new ResponseEntity<Object>(result, HttpStatus.CREATED);

      return responseEntity;
    } catch (Exception ex) {
      ex.printStackTrace();
      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());
      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);
      return responseEntity;
    }

  }


  /**
   * 开始活动活动.
   *
   * @param activityId 活动id
   * @param passengerId 客户id
   * @param enterpriseId 企业客户id
   * @param appKey 系统key
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "startActivity", method = RequestMethod.POST)
  public ResponseEntity<Object> startActivity(
      @RequestParam(required = true, value = "activityId") Long activityId, @RequestParam(
          required = true, value = "passengerId") Long passengerId, @RequestParam(required = false,
          value = "enterpriseId") Long enterpriseId, @RequestParam(required = true,
          value = "appKey") String appKey) {

    ResponseEntity<Object> responseEntity = null;

    try {

      ActivityRecord activityRecord =
          activityManager.startActivity(activityId, passengerId, enterpriseId, appKey);

      Result<ActivityRecord> result = new Result<ActivityRecord>(0, "成功", activityRecord);
      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {
      ex.printStackTrace();

      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());

      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

      return responseEntity;
    }

  }

  /**
   * 开始活动活动.
   *
   * @param activityId 活动id
   * @param passengerId 客户id
   * @param enterpriseId 企业客户id
   * @param appKey 系统key
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "startActivityV4", method = RequestMethod.POST)
  public ResponseEntity<Object> startActivityV4(
      @RequestParam(required = true, value = "activityId") Long activityId, @RequestParam(
          required = true, value = "passengerId") Long passengerId, @RequestParam(required = false,
          value = "enterpriseId") Long enterpriseId, @RequestParam(required = true,
          value = "appKey") String appKey) {

    ResponseEntity<Object> responseEntity = null;

    try {

      ActivityVo activityVo = activityManager.startActivityV4(activityId, passengerId, enterpriseId, appKey);

      Result<ActivityVo> result = new Result<ActivityVo>(0, "成功", activityVo);
      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {
      ex.printStackTrace();

      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());

      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

      return responseEntity;
    }

  }

  /**
   * 停止活动.
   * 
   * @param activityId 活动id
   * @param appKey 系统key
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "stopActivity/{activityId}", method = RequestMethod.PUT)
  public ResponseEntity<Object> stopActivity(@PathVariable("activityId") Long activityId,
      @RequestParam("appKey") String appKey) {

    ResponseEntity<Object> responseEntity = null;

    appKey = StringUtils.trimToEmpty(appKey);

    try {
      activityManager.stopActivity(activityId, appKey);

      Result<Activity> result = new Result<Activity>(0, "成功", null);
      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {
      ex.printStackTrace();
      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());
      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);
      return responseEntity;
    }

  }

  /**
   * 删除活动.
   * 
   * @param activityId 活动id
   * @param appKey 系统key
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "deleteActivity/{activityId}", method = RequestMethod.PUT)
  public ResponseEntity<Object> deleteActivity(@PathVariable("activityId") Long activityId,
      @RequestParam("appKey") String appKey) {

    ResponseEntity<Object> responseEntity = null;

    appKey = StringUtils.trimToEmpty(appKey);

    try {
      activityManager.deleteActivity(activityId, appKey);

      Result<Activity> result = new Result<Activity>(0, "成功", null);
      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {
      ex.printStackTrace();
      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());
      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);
      return responseEntity;
    }

  }


  /**
   * 查询有效活动.
   * 
   * @param activityEvent 活动事件
   * @param appKey 系统key
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "findValidByEvent", method = RequestMethod.GET)
  public ResponseEntity<Object> findValidByEvent(@RequestParam(required = false,
      value = "activityEvent") String activityEvent, @RequestParam(required = true,
      value = "appKey") String appKey) {

    ResponseEntity<Object> responseEntity = null;

    try {

      List<Activity> activities = activityManager.listValidByEvent(activityEvent, appKey);

      Result<List<Activity>> result = new Result<List<Activity>>(0, "成功", activities);
      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {
      ex.printStackTrace();
      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());

      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

      return responseEntity;
    }

  }

  /**
   * 根据companyId查询有效首单免费活动.
   *
   * @param companyId 公司id
   * @param appKey 系统key
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "findOneFree", method = RequestMethod.GET)
  public ResponseEntity<Object> findOneFree(
      @RequestParam(required = true, value = "companyId") Long companyId, @RequestParam(
          required = true, value = "appKey") String appKey) {

    ResponseEntity<Object> responseEntity = null;

    try {

      List<Activity> activity = activityManager.findOneFreeActivity(companyId, appKey);

      Result<List<Activity>> result = new Result<List<Activity>>(0, "成功", activity);
      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {
      ex.printStackTrace();
      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());

      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

      return responseEntity;
    }

  }


  /**
   * 根据ID查询单个活动.
   *
   * @param activityId 活动id
   * @param appKey 系统key
   * @return ResultTransport{code,message,data}
   */
  @RequestMapping(value = "{activityId}", method = RequestMethod.GET)
  public ResponseEntity<Object> getActivity(@PathVariable("activityId") Long activityId,
      @RequestParam("appKey") String appKey) {
    ResponseEntity<Object> responseEntity = null;

    appKey = StringUtils.trimToEmpty(appKey);

    Activity activity = activityManager.findOne(activityId, appKey);
    try {

      Result<Activity> result = new Result<Activity>(0, "成功", activity);

      responseEntity = new ResponseEntity<Object>(result, HttpStatus.OK);

      return responseEntity;

    } catch (Exception ex) {

      Error error = new Error(500, "内部服务器错误：" + ex.getMessage());

      responseEntity = new ResponseEntity<Object>(error, HttpStatus.INTERNAL_SERVER_ERROR);

      return responseEntity;
    }
  }



}
